﻿using System;
using System.Text;
using System.Collections.Generic;

using NUnit.Framework;
using System.Diagnostics;

namespace GotLyrics.UnitTest
{
    /// <summary>
    /// Summary description for UltraGrabberTest
    /// </summary>
    [TestFixture]
    public class UltraGrabberTest
    {
        public UltraGrabberTest()
        {
            //
            // TODO: Add constructor logic here
            //
        }
      
        [Test]
        public void ExecuteDirectoryTest()
        {
            UltraGrabber ultraGrabber = new UltraGrabber();

            ultraGrabber.Filename = TestCommon.Mp3RootDir;
            
            ultraGrabber.ScanDirectory += new EventHandler<ScanDirectoryEventArgs>(UltraGrabber_ScanDirectory);
            ultraGrabber.ProcessFileBegin += new EventHandler<ProcessFileEventArgs>(UltraGrabber_ProcessFile);
            ultraGrabber.ProcessFileError += new EventHandler<ProcessFileErrorEventArgs>(UltraGrabber_ProcessFileError);
            ultraGrabber.ExecutingGrabber += new EventHandler<ExecutingGrabberEventArgs>(UltraGrabber_ExecutingGrabber);
            ultraGrabber.LyricsFound += new EventHandler<LyricsFoundEventArgs>(UltraGrabber_LyricsFound);

            ultraGrabber.Execute();
        }

        void UltraGrabber_LyricsFound(object sender, LyricsFoundEventArgs e)
        {
            Debug.WriteLine("The grabber " + e.LyricGrabber.Name + " has found lyrics for the file \"" + e.Context.Filename + "\".");
            Debug.WriteLine(e.Lyrics);
        }

        void UltraGrabber_ExecutingGrabber(object sender, ExecutingGrabberEventArgs e)
        {
            Debug.WriteLine("Executing grabber \"" + e.LyricGrabber.Name + "\" for file \"" + e.Context.Filename + "\".");
        }

        void UltraGrabber_ProcessFileError(object sender, ProcessFileErrorEventArgs e)
        {
            Debug.WriteLine("Error occured while processing file \"" + e.Filename + "\"");
            Debug.WriteLine(e.Exception.ToString());
        }

        void UltraGrabber_ProcessFile(object sender, ProcessFileEventArgs e)
        {
            Debug.WriteLine("Processing file: \"" + e.Context.Filename + "\"");
        }

        void UltraGrabber_ScanDirectory(object sender, ScanDirectoryEventArgs e)
        {
            Debug.WriteLine("Scanning folder: \"" + e.Directory + "\"");
        }
    }
}
